package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDrom;
import com.ruoyi.system.service.ISysDromService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * dromController
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/system/DORM")
public class SysDromController extends BaseController
{
    private String prefix = "system/DORM";

    @Autowired
    private ISysDromService sysDromService;

    @RequiresPermissions("system:DORM:view")
    @GetMapping()
    public String DORM()
    {
        return prefix + "/DORM";
    }

    /**
     * 查询drom列表
     */
    @RequiresPermissions("system:DORM:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysDrom sysDrom)
    {
        startPage();
        List<SysDrom> list = sysDromService.selectSysDromList(sysDrom);
        return getDataTable(list);
    }

    /**
     * 导出drom列表
     */
    @RequiresPermissions("system:DORM:export")
    @Log(title = "drom", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysDrom sysDrom)
    {
        List<SysDrom> list = sysDromService.selectSysDromList(sysDrom);
        ExcelUtil<SysDrom> util = new ExcelUtil<SysDrom>(SysDrom.class);
        return util.exportExcel(list, "drom数据");
    }

    /**
     * 新增drom
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存drom
     */
    @RequiresPermissions("system:DORM:add")
    @Log(title = "drom", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysDrom sysDrom)
    {
        return toAjax(sysDromService.insertSysDrom(sysDrom));
    }

    /**
     * 修改drom
     */
    @GetMapping("/edit/{dormCrew}")
    public String edit(@PathVariable("dormCrew") String dormCrew, ModelMap mmap)
    {
        SysDrom sysDrom = sysDromService.selectSysDromByDormCrew(dormCrew);
        mmap.put("sysDrom", sysDrom);
        return prefix + "/edit";
    }

    /**
     * 修改保存drom
     */
    @RequiresPermissions("system:DORM:edit")
    @Log(title = "drom", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysDrom sysDrom)
    {
        return toAjax(sysDromService.updateSysDrom(sysDrom));
    }

    /**
     * 删除drom
     */
    @RequiresPermissions("system:DORM:remove")
    @Log(title = "drom", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysDromService.deleteSysDromByDormCrews(ids));
    }
}
